﻿
#include <osg/Group>  
#include <osg/PolygonMode>
#include <osg/ShapeDrawable>
#include <osgDB/ReadFile>  
#include <osgUtil/PrintVisitor>  
#include <osgViewer/ViewerEventHandlers>  
#include <osgViewer/Viewer>  
#include <iostream>  
#include <fstream>  
#include <sstream>  
#include <OsgExTool/OsgExTool>
#include <OsgExTool/OsgExTool2>
#include <DebugTool/DebugFunction>

#include <osg/ComputeBoundsVisitor>
#include <BaseTool/BaseTool>

#include <osgDB/FileUtils>

#include <OsgExTool/MergeGeometry>
#include <OsgExTool/BigTextureText>

#include <osg/LightModel>

//
#include <osgUtil/ReflectionMapGenerator>
#include <osgUtil/HighlightMapGenerator>
#include <osgUtil/HalfWayMapGenerator>

#include <osg/TexEnvCombine>

#include <osgText/Text3D>

#include <osg/Stencil>

#include <OsgExTool/DisplayEffect>"

using namespace OsgExTool;


//创建场景数据
//osg::ref_ptr<osg::Node> DisplayEffect::createModel()
//{
//	osg::Vec3 center(0.0f, 0.0f, 0.0f);
//	float radius = 100.0f;
//	osg::Vec3 lightPosition(center + osg::Vec3(0.0f, 0.0f, radius));
//
//	osg::ref_ptr<osg::Node> shadower = osgDB::readNodeFile("D:\\OSGmodel\\WKZ005_JZ_24.OSGB");
//	shadower->setNodeMask(CastsShadowTraversalMask);
//
//	osg::ref_ptr<osg::Node> shadowed = osgDB::readNodeFile("D:\\OSGmodel\\floor.OSGB");
//	shadowed->setNodeMask(ReceivesShadowTraversalMask);
//
//	osg::ref_ptr<osg::Group> group = new osg::Group;
//
//	group->addChild(shadowed.get());
//	group->addChild(shadower.get());
//
//	return group.get();
//}

//创建一个光照
osg::ref_ptr<osg::Node> DisplayEffect::createLight(osg::BoundingBox& bb)
{
	osg::Vec4 lightpos;

	lightpos.set(bb.center().x(), bb.center().y(), bb.center().z(), 1.0f);

	osg::ref_ptr<osg::LightSource> ls = new osg::LightSource();
	ls->getLight()->setPosition(lightpos);

	ls->getLight()->setAmbient(osg::Vec4(0.2, 0.2, 0.2, 1.0));
	ls->getLight()->setDiffuse(osg::Vec4(0.8, 0.8, 0.8, 1.0));

	return ls.get();
}

//返回的模型加上光源和模型，然后挂上根节点
osg::ref_ptr<osgShadow::ShadowedScene> DisplayEffect::createShadowMap()
{
	//创建一个阴影节点，并标识接收对象和投影对象
	osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene();
	shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
	shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask);

	//创建阴影纹理
	osg::ref_ptr<osgShadow::ShadowMap> st = new osgShadow::ShadowMap();
	//关联阴影纹理
	shadowedScene->setShadowTechnique(st);

	//osg::ref_ptr<osg::Node> node = new osg::Node();
	//node = createModel();

	//添加场景数据并添加光源
	//shadowedScene->addChild(createLight(model.get())); //添加光源
	//shadowedScene->addChild(model.get()); //添加模型
	return shadowedScene;
}




